package org.rcgwt.client.ui.validator.impl;

import java.util.Map;

import org.rcgwt.client.ui.validator.ICharacterSets;
import org.rcgwt.client.ui.validator.IClientValidatorContext;
import org.rcgwt.client.ui.validator.IFilter;
import org.rcgwt.client.util.Pattern;

/**
 * A date filter which filter all characters except separator-signs or digits
 * 
 * @author Elian ORIOU
 * 
 */

public class DateFilter implements IFilter {
	private static final String MY_PATTERN = ICharacterSets.NUM_SET;

	private char sepSign = '/';

	public DateFilter(Map<String, String> parameters) {

		// Separator Sign
		if (parameters.containsKey("date.sepSign")) {
			sepSign = parameters.get("date.sepSign").charAt(0);
		}
	}

	@Override
	public boolean filter(IClientValidatorContext context, char c) {

		/* If the character is a separator-sign or a digit */
		if (MY_PATTERN.indexOf(c) != -1 || c == sepSign) {
			return true;
		}
		return false;
	}
}
